import { useAuthed } from '~/composables/useAuthed';
import { useUserStore } from '~/stores/user';

export default defineRoute(() => [
  {
    path: '/referral',
    component: Layouts.default,
    async beforeEnter(to, from) {
      // 基于用户类型限制访问
      const userInfo = await apis.apiUserInfo(undefined).catch(() => {});
      if (userInfo?.type === 7)
        return from;

      return true;
    },
    children: [
      {
        path: '',
        name: RN.REFERRAL,
        component: () => import('./index/index.vue'),
        redirect: { name: RN.REFERRAL_DASHBOARD },
        beforeEnter: () => {
          return useAuthed().value || { name: RN.REFERRAL_ABOUT };
        },
        children: [
          {
            path: 'dashboard',
            name: RN.REFERRAL_DASHBOARD,
            component: () => import('./index/dashboard/index.vue'),
          },
          {
            path: 'campaigns',
            name: RN.REFERRAL_CAMPAIGNS,
            component: () => import('./index/campaigns/index.vue'),
          },
          {
            path: 'referrals',
            name: RN.REFERRAL_REFERRALS,
            component: () => import('./index/referrals/index.vue'),
          },
        ],
      },
      {
        path: 'about',
        component: () => import('./about/index.vue'),
        name: RN.REFERRAL_ABOUT,
      },
    ],
  },
]);
